// miniprogram/pages/main/release-page/release-page.js
const utils = require('../../../util/common.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    maxImageListLength:6,
    maxImageSize:-1,
    commentBottom:0,
    releaseContentTop:0,
    choosedImages:[],
    topBarHeight: app.globalData.systemInfo.statusBarHeight + wx.getMenuButtonBoundingClientRect().height + (wx.getMenuButtonBoundingClientRect().top - app.globalData.systemInfo.statusBarHeight) * 2,
    statusBarHeight: app.globalData.systemInfo.statusBarHeight,
    icons:{
      pen:'',
      left:'',
      imgBtn:'',
      locationBtn:'',
      stateBtn:'',
      deleteBtn:''
    }
  },
  //删除已选择的图片
  deleteChoosedImage:function(e){
    console.log(JSON.stringify(e))
  
    let idx =  e.target.dataset.idx;
    let newList = this.data.choosedImages;
    
    newList.splice(idx,1);
    this.setData({choosedImages:newList});
  },
    // 选择图片
  chooseImage:function(e){
    let that = this;
    wx.chooseImage({
      success: function (res) {
        console.log(JSON.stringify(res))
        if(res.tempFiles.length>that.data.maxImageListLength){
          
        }else{
        that.setData({
          choosedImages: res.tempFiles.map(i=>{if(that.data.maxImageSize===-1||i.size<=that.data.maxImageSize){
            return i.path;
          }})
        })
      }
      },
    })
  },
  putCommentUp:function(e){
    this.setData({
      commentBottom: e.detail.height
    })
  },
  dismissComment: function () {
    this.setData({
      commentBottom: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获取发布输入框顶部的距离
    utils.getElementTopDistance('headerBar',({top,bottom})=>{
      this.setData({releaseContentTop: bottom});
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})